resourceloader: Use mw.log instead of 'throw' for scripts with syntax errors
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 1 Jun 2015 23:06:46 +0000 (00:06 +0100)
committerOri.livneh <ori@wikimedia.org>
Tue, 2 Jun 2015 22:43:46 +0000 (22:43 +0000)
For scripts loaded from load.php using mw.loader.implement(), an
exception is handled fine and results in the module state progressing
from 'loading' to 'errror'.

However, for wikis modules loaded with only=scripts from the HTML directly,
there is no wrapper. As such, the state() call appended to the script is
never reached and the module indefinitely stays "loading".

VisualEditor (and others) already explicitly ignore the error state
of the wiki modules (with inline mw.loader.using and casting the Promise to resolved).
However in this case the Promise never completed to neither success nor failure.

As such, this was causing users with syntax errors in their user script to
encounter a stuck VisualEditor loading bar that never goes beyond 70%.

Change-Id: I091a020bdd3392b965e0e25d03b216037fadc48f

includes/resourceloader/ResourceLoaderModule.php

index 57634ab..958990c 100644 (file)
@@ -640,7 +640,7 @@ abstract class ResourceLoaderModule {
                        } catch ( Exception $e ) {
                                // We'll save this to cache to avoid having to validate broken JS over and over...
                                $err = $e->getMessage();
-                               $result = "throw new Error(" . Xml::encodeJsVar( "JavaScript parse error: $err" ) . ");";
+                               $result = "mw.log.error(" . Xml::encodeJsVar( "JavaScript parse error: $err" ) . ");";
                        }
 
                        $cache->set( $key, $result );